<template>
  <div class="playlist-container">
    <div class="top-wrap">
      <div class="img-wrap">
        <img :src="playlist.coverImgUrl" alt="" />
      </div>
      <div class="info-wrap">
        <p class="title">{{ playlist.name }}</p>
        <div class="author-wrap">
          <img class="avatar" :src="playlist.creator? playlist.creator.avatarUrl : ''" alt="" />
          <span class="name">{{ playlist.creator ? playlist.creator.nickname  :''}}</span>
          <span class="time">{{ playlist.createTime }} 创建</span>
        </div>
        <div class="play-wrap">
          <span class="iconfont icon-circle-play"></span>
          <span class="text">播放全部</span>
        </div>
        <div class="tag-wrap">
          <span class="title">标签:</span>
          <ul>
            <li v-for="(k,index) in playlist.tags" :key="index">{{ k }}</li>
          </ul>
        </div>
        <div class="desc-wrap">
          <span class="title">简介:</span>
          <span class="desc">{{ playlist.description }}</span>
        </div>
      </div>
    </div>
    <el-tabs v-model="activeIndex">
      <el-tab-pane label="歌曲列表" name="1">
        <table class="el-table playlit-table">
          <thead>
            <th></th>
            <th></th>
            <th>音乐标题</th>
            <th>歌手</th>
            <th>专辑</th>
            <th>时长</th>
          </thead>
          <tbody>
            <tr class="el-table__row" v-for="(k,index) in playlist.tracks" :key="index" @click="playMusic(k.id)">
              <td>{{ index+1 }}</td>
              <td>
                <div class="img-wrap">
                  <img :src="k.al.picUrl" alt="" />
                  <span class="iconfont icon-play"></span>
                </div>
              </td>
              <td>
                <div class="song-wrap">
                  <div class="name-wrap">
                    <span>{{ playlist.tracks.name }}</span>
                    <span class="iconfont icon-mv"></span>
                  </div>
                  <span>{{ k.name }}</span>
                </div>
              </td>
              <td>{{ k.ar[0].name }}</td>
              <td>{{ playlist.name }}</td>
              <td>{{ k.publishTime }}</td>
            </tr>
          </tbody>
        </table>
      </el-tab-pane>
      <el-tab-pane label="评论" name="2">
        <!-- 精彩评论 -->
        <div class="comment-wrap">
          <p class="title">精彩评论:  <span class="number">{{ (hotCount) }}</span></p>
          <div class="comments-wrap">
            <!-- 评论 -->
            <div class="item" v-for="(k,index) in hotComment" :key="index">
              <div class="icon-wrap">
                <!-- 头像 -->
                <img :src="k.user ? k.user.avatarUrl : ''" alt="" />
              </div>
              <div class="content-wrap">
                <div class="content">
                  <span class="name">{{ k.user.nickname+':     ' }}</span>
                  <span class="comment">{{ k.content }}</span>
                </div>
                <!-- 评论回复 -->
                <div class="re-content" v-if="k.beReplied.length!=0">
                  <span class="name">{{ k.beReplied[0].user.nickname+':  ' }}</span>
                  <span class="comment">{{ k.beReplied[0].content }}</span>
                </div>
                <div class="date">{{k.time}}</div>
              </div>
            </div>
          </div>
        </div>
        <!-- 最新评论 -->
        <div class="comment-wrap">
          <p class="title">最新评论<span class="number">({{ total }})</span></p>
          <div class="comments-wrap" v-for="(k,index) in comments" :key="index">
            <div class="item">
              <div class="icon-wrap">
                <img :src="k.user ? k.user.avatarUrl : ''" alt="" />
              </div>
              <div class="content-wrap">
                <div class="content">
                  <span class="name">{{ k.user.nickname+':   ' }}</span>
                  <span class="comment">{{ k.content }}</span>
                </div>
                <div class="re-content" v-if="k.beReplied.length!=0">
                  <span class="name">{{ k.beReplied[0].user.nickname+':  ' }}</span>
                  <span class="comment">{{ k.beReplied[0].content }}</span>
                </div>
                <div class="date">{{ k.time }}</div>
              </div>
            </div>
          </div>
        </div>
        <!-- 分页器 -->
        <el-pagination
          @current-change="handleCurrentChange"
          background
          layout="prev, pager, next"
          :total="total"
          :current-page="page"
          :page-size="5"
        >
        </el-pagination>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
// import moment from 'moment'

export default {
    data() {
        return {
            activeIndex:'1',
            total:0, //条数
            page:1, // 页码
            //歌单详情 tracks
            playlist:{},
            //热门评论
            hotComment:[],
            //热门评论个数
            hotCount:0,
            //最新评论
            comments:[]
        }
    },
    created(){
        this.getPlaylists()
    },
    methods:{
        getPlaylists(){
            //获取歌单详情
            this.axios.get('playlist/detail',{
                params:{
                    id:this.$route.query.id
                }
            }).then(res=>{
                // console.log(res);
                this.playlist = res.data.playlist
                console.log(this.playlist);
            })
            //获取评论
            this.axios.get('comment/hot',{
                params:{
                    id:this.$route.query.id,
                    type:2
                }
            }).then(res=>{
                // console.log(res);
                this.hotComment = res.data.hotComments
                //热门评论个数
                this.hotCount = res.data.total
                //处理时间
                //  console.log( this.hotComment);
                // 2022/12/19
                for(let i =0;i<this.hotComment.length;i++){
                   if(this.hotComment){
                      this.hotComment[i].time = this.$moment().format('MMMM Do YYYY, h:mm:ss a')
                   }
                }
            })
            //获取最新评论
            this.axios.get('comment/playlist',{
                params:{
                    id:this.$route.query.id,
                    limit:10,
                    offset:0
                }
            }).then(res=>{
                //总个数
                this.total = res.data.total
                //评论
                this.comments = res.data.comments
                // console.log(this.comments);
                //评论时间
                for(let i = 0;i<this.comments.length;i++){
                  this.comments[i].time= this.$moment().format('MMMM Do YYYY, h:mm:ss a')
                }
            })
        },
        handleCurrentChange(val){
            this.page = val
             //页面重新获取数据
            this.axios.get('comment/playlist',{
                params:{
                   id:this.$route.query.id,
                   limit:10,
                   offset: (this.page - 1) * 10,
                }
            }).then(res=>{
             // 总个数
            this.total = res.data.total
             // 评论数据
             this.comments = res.data.comments
          })
        },
        playMusic(id){
          this.$emit('srcChange',id)
          
        }
    }
}
</script>

<style>

</style>